import asyncio
import os
from pyppeteer import launch

async def main():
    # 网站列表
    path = os.path.dirname(os.path.abspath(__file__))
    url_file = os.path.join(path, 'url.txt')

    # 读取网站列表
    with open(url_file, 'r') as file:
        websites = file.readlines()

    browser = await launch(headless=False, args=['--ignore-certificate-errors'])  # 打开 Chrome 浏览器
    page = await browser.newPage()

    for website in websites:
        website = website.strip()  # 去除换行符等空白字符
        try:
            await page.goto(website)
            print(f"Successfully fetched {website}")
            # 在这里添加其他操作，例如等待页面加载完成
        except Exception as e:
            print(f"Error fetching {website}: {e}")

    # 等待浏览器关闭
    await browser.close()

# 运行主函数
asyncio.get_event_loop().run_until_complete(main())
